package com.wnxy.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.wnxy.admin.common.ResponseResult;
import com.wnxy.admin.entity.Staff;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import com.wnxy.admin.entity.Role;
import com.wnxy.admin.service.IRoleService;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author All
 * @since 2023-11-29
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    private final IRoleService roleServiceImpl;
    public RoleController(IRoleService roleServiceImpl){
        this.roleServiceImpl = roleServiceImpl;
    }

    //分页，模糊查询
    @GetMapping("/page/{pageNum}/{pageSize}")
    public ResponseResult page(@PathVariable Integer pageNum,
                               @PathVariable Integer pageSize,
                               @RequestParam(required = false) String keyword) {
        PageInfo<Staff> page = roleServiceImpl.getAll(pageNum, pageSize, keyword);
        return ResponseResult.ok(page);
    }

    //新增
    @PostMapping("/add")
    public ResponseResult add(@RequestBody Role role) {
        roleServiceImpl.add(role);
        return ResponseResult.ok();
    }

    //编辑
    @PostMapping("/update")
    public ResponseResult update(@RequestBody Role role) {
        roleServiceImpl.updateById(role);
        return ResponseResult.ok();
    }

    //数据库删除
    @PostMapping("/delete/{id}")
    public ResponseResult delete(@PathVariable("id") Integer id) {
        roleServiceImpl.deleteRole(id);
        return ResponseResult.ok();
    }

    //根据id获取客户
    @GetMapping("/getById")
    public ResponseResult getById(Integer roleId) {
        Role role = roleServiceImpl.getById(roleId);
        return ResponseResult.ok(role);
    }

    //获取全部
    @GetMapping("/getAll")
    public ResponseResult getAll() {
        List<Role> list = roleServiceImpl.list();
        return ResponseResult.ok(list);
    }


}
